/*
 * @Author: your name
 * @Date: 2021-09-01 09:42:54
 * @LastEditTime: 2021-09-01 16:04:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day08\1-exec.js
 */

//全词匹配 g 
var pattern = /abc/g;
var str = 'ababc ac ab abcd we';
//exec() 从参数中获取目标字符串
//index: 匹配的字符串开始的索引下标
//lastIndex:匹配的字符串结束的下一个索引下标

//第一次查找
console.log(pattern.exec(str)); //[ 'abc', index: 2, input: 'ababc ac ab abcd we', groups: undefined ]
console.log('lastIndex:' + pattern.lastIndex); //lastIndex:5
//第二次查找
console.log(pattern.exec(str)); //[ 'abc', index: 12, input: 'ababc ac ab abcd we', groups: undefined ]
console.log('lastIndex:' + pattern.lastIndex); //lastIndex:15
//第三次查找
console.log(pattern.exec(str)); //null
console.log('lastIndex:' + pattern.lastIndex); //lastIndex:0

//大小写
var pattern = /abc/ig;
var str = 'abaBc ac ab abcd we';
console.log(pattern.exec(str)); //[ 'aBc', index: 2, input: 'abaBc ac ab abcd we', groups: undefined ]
console.log('lastIndex:' + pattern.lastIndex); //lastIndex:5
console.log(pattern.exec(str)); //[ 'abc', index: 12, input: 'abaBc ac ab abcd we', groups: undefined ]
console.log('lastIndex:' + pattern.lastIndex); //lastIndex:15
console.log(pattern.exec(str)); //null
console.log('lastIndex:' + pattern.lastIndex); //lastIndex:0